package com.seio.edc.controller.business;

import javax.servlet.http.HttpServletRequest;

import com.nova.edc.model.system.PointLight;
import com.nova.edc.service.system.PointLightService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.nova.edc.model.system.CollectAreaItem;
import com.nova.edc.model.system.CustomerInfo;
import com.nova.edc.service.system.CollectAreaItemAirService;
import com.nova.edc.service.system.CollectAreaItemService;
import com.nova.edc.service.system.CustomerInfoService;
import com.nova.frame.dao.pager.Page;
import com.nova.frame.dao.pager.PageList;
import com.seio.edc.util.DateTimeUtil;

/**
 * 项目实施方案
 *
 * @author Administrator
 */
@Controller
@RequestMapping(value = "/business")
public class BusinessContoller {

    private static Logger log = Logger.getLogger(BusinessContoller.class);

    @Autowired
    private CustomerInfoService novaCustomerInfoService;

    @Autowired
    private CollectAreaItemService novaCollectAreaItemService;

    @Autowired
    private PointLightService pointLightService;

    private static final int PAGE_SIZE = 10;

    /**
     * 项目实施方案初期页面
     *
     * @param request
     * @param modelMap
     * @param
     * @return
     */
    @RequestMapping(value = "init")
    public ModelAndView init(HttpServletRequest request, ModelMap modelMap,
                             Integer pageIndex, CollectAreaItem collectAreaItem,
                             Integer companycode) {
        log.info("项目实施方案开始："
                + DateTimeUtil.getNowTime(DateTimeUtil.YYYY_MM_DD_HH_MM_SS));

        // 登录用户所属公司名称设定到session中
        CustomerInfo customerInfo = novaCustomerInfoService
                .getByCompanyCode(companycode);
        modelMap.put("customerInfo", customerInfo);
        modelMap.put("companycode", companycode);
        modelMap.put("customername", customerInfo.getCustomername());
        // 当前页数
        Page page = new Page();
        page.setCurrentPage(pageIndex == null || pageIndex == 0 ? 1 : pageIndex);
        page.setPageSize(PAGE_SIZE);
        modelMap.put("pageIndex", page.getCurrentPage());
        collectAreaItem.setCompanycode(companycode);
        // 获取项目实施详情
        PointLight pointLight = new PointLight();
        pointLight.setCustomerinfoid(customerInfo.getId());
        PageList<PointLight> pageList = pointLightService.findPageExecute(pointLight, page, "ID", "asc");
//        PageList<CollectAreaItem> pageList = novaCollectAreaItemService
//                .findCollectAreaItemPageList(collectAreaItem, page, "ID", "asc");
        modelMap.put("dataCount", page.getRowCount());
        modelMap.put("pageCount", page.getTotalPage());

        // 数据列表
        modelMap.put("listdata", pageList.getDatas());
//		modelMap.put("trdhjp",
//				novaCollectAreaItemService.getTraLightPower(companycode));
//		modelMap.put("ledhjp",
//				novaCollectAreaItemService.getLedLightPower(companycode));
        log.info("项目实施方案结束："
                + DateTimeUtil.getNowTime(DateTimeUtil.YYYY_MM_DD_HH_MM_SS));
        return new ModelAndView("business/prjimpmth", modelMap);
    }


}
